﻿using Autofac;
using FaceWebServer.DB;
using FaceWebServer.Interface;
using FaceWebServer.Service;
using FaceWebServer.Utility;
using Microsoft.AspNetCore.Mvc.ApplicationParts;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.EntityFrameworkCore;
using System.Linq;
using System.Reflection;

namespace FC8280TServer
{
    public class CustomAutofacModule : Autofac.Module
    {
        protected override void Load(ContainerBuilder containerBuilder)
        {
            //var assembly = this.GetType().GetTypeInfo().Assembly;
            //var builder = containerBuilder;
            //var manager = new ApplicationPartManager();
            //manager.ApplicationParts.Add(new AssemblyPart(assembly));
            //manager.FeatureProviders.Add(new ControllerFeatureProvider());
            //var feature = new ControllerFeature();
            //manager.PopulateFeature(feature);
            //builder.RegisterType<ApplicationPartManager>().AsSelf().SingleInstance();
            //builder.RegisterTypes(feature.Controllers.Select(ti => ti.AsType()).ToArray()).PropertiesAutowired();


            containerBuilder.RegisterType<MyMemoryCache>().As<IMyMemoryCache>().SingleInstance().PropertiesAutowired();
            containerBuilder.RegisterType<FaceDBContext>().As<DbContext>();
            containerBuilder.RegisterType<RecordService>().As<IRecordService>().PropertiesAutowired();
            containerBuilder.RegisterType<SystemMenuService>().As<ISystemMenuService>().PropertiesAutowired();
            containerBuilder.RegisterType<UserService>().As<IUserService>().PropertiesAutowired();
            containerBuilder.RegisterType<FaceDriveService>().As<IFaceDriveService>().PropertiesAutowired();
            containerBuilder.RegisterType<PeopleService>().As<IPeopleService>().PropertiesAutowired();
            containerBuilder.RegisterType<TimeGroupService>().As<ITimeGroupService>().PropertiesAutowired();
            containerBuilder.RegisterType<DeviceRemoteService>().As<IDeviceRemoteService>().PropertiesAutowired();
            containerBuilder.RegisterType<ConnectIOLogService>().As<IConnectIOLogService>();
            containerBuilder.RegisterType<CacheService>().As<ICacheService>(); 


        }
    }
}